package com.cn.wanxi.thread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class MyCallableTest {
    public static void main(String[] args) throws Exception {
//        MyCallable myCallable=new MyCallable();
//        myCallable.call();
        ExecutorService threadPool = Executors.newSingleThreadExecutor();   // 启动线程
        Future<String> future = threadPool.submit(new MyCallable());
//        匿名类
//        Future<String> future = (Future<String>) threadPool.submit(new Runnable() {
//            @Override
//            public void run() {
//                System.out.println("aaa");
//            }
//        });

        try {
            Thread.currentThread().setName("aaa");
            System.out.println("waiting thread to finish");
            System.out.println(future.get()); // 等待线程结束，并获取返回结果
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
